package com.example.newproject_overseas.ViewModel

import android.util.Log
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.navigation.NavHostController
import com.example.newproject_overseas.exception.NetworkExceptionHandler
import com.example.newproject_overseas.model.entity.GetOrderRequest
import com.example.newproject_overseas.model.entity.GetOrderRequestBody
import com.example.newproject_overseas.model.service.base.GetOrderServices

class GetOrderViewModel : ViewModel() {
    var status by mutableStateOf<String?>(null)

    private val OrderServices = GetOrderServices.instance()

    suspend fun OrderServicesReq(navController: NavHostController, newIndex: Int) {
        when (newIndex) {
            0 -> {
            }

            1 -> {
                status = "LOAN_SUCCESS"
            }

            2 -> {
                status = "DUNNING"
            }

            3 -> {
                status = "FINISH"
            }
        }
        val cenobitismReq = GetOrderRequestBody(status = status, pageNo = 1, pageSize = 10);
        val cenobitismBody = GetOrderRequest(cenobitismReq);
        try {
            val cenobitismResp = OrderServices.GetOrderinterface(cenobitismBody)

            if (cenobitismResp.status == 0) {
                Log.i("成功了", cenobitismResp.toString())
                //数据
                val model = cenobitismResp.page

            }
            // 处理正常的响应逻辑
        } catch (e: Exception) {
            Log.i("失败了", e.toString())
            NetworkExceptionHandler.handleException(e, navController)
        }
    }
}